package com.jzo2o.market.service.impl;

import com.github.pagehelper.PageHelper;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.market.mapper.CouponMapper;
import com.jzo2o.market.model.dto.request.CouponOperationPageQueryReqDTO;
import com.jzo2o.market.model.dto.response.CouponInfoResDTO;
import com.jzo2o.market.service.ICouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LeeC
 * @description
 * @date 2025/2/12
 * @PACKAGE_NAME com.jzo2o.market.service.impl
 */
@Service
public class CouponServiceImpl implements ICouponService {
    @Resource
    private CouponMapper couponMapper;

    @Override
    public List<CouponInfoResDTO> my(Long status, Long lastId) {
        return couponMapper.selectByStatus(status,lastId);
    }

    @Override
    public PageResult<CouponInfoResDTO> page(CouponOperationPageQueryReqDTO pageReqDTO) {
        PageHelper.startPage(pageReqDTO.getPageNo().intValue(), pageReqDTO.getPageSize().intValue());
        List<CouponInfoResDTO> page = couponMapper.page(pageReqDTO);
        Long total = (long) page.size();
        Long pages = total % pageReqDTO.getPageSize() ==0 ?total / pageReqDTO.getPageSize():total / pageReqDTO.getPageSize()+1;
        return new PageResult<>(pages, total , page);
    }
}
